package cn.itsource.product.service.impl;

import cn.itsource.basic.service.impl.BasicServiceImpl;
import cn.itsource.product.domain.Product;
import cn.itsource.product.domain.ProductDetail;
import cn.itsource.product.mapper.ProductDetailMapper;
import cn.itsource.product.mapper.ProductMapper;
import cn.itsource.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductServiceImpl extends BasicServiceImpl<Product>  implements IProductService{
    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductDetailMapper productDetailMapper;

    //批量上架
    @Override
    public void onSale(Long[] ids) {
        productMapper.onSale(ids);
    }

    @Override
    @Transactional
    public void add(Product product) {
        //先保存产品对象 返回主键
        productMapper.save(product);
        //
        ProductDetail detail = product.getDetail();
        //设置关联对象
        //detail.setProduct_id(product.getId());
        detail.setProduct(product);
        //保存产品详情
        productDetailMapper.save(detail);

    }
}
